package thing

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"iot-base/auth/common"
	Log "iot-base/auth/logger"
	types2 "iot-base/auth/types"
	"iot-base/common/ctrltype"
)

func AirConditioningSwitch(c *gin.Context) {
	requestId, _ := c.Get("RequestId")
	uid := c.GetInt64("uid")
	resp := types2.NewResult(c)
	var req types2.ReqAirConditioningSwitch
	if err := c.ShouldBind(&req); err != nil {
		Log.Log.Errorf("[%s] [%v] err:=%v", requestId, uid, err)
		resp.ErrorCode(types2.ParamsError, "")
		return
	}
	var cmd ctrltype.CtrlCmd
	cmd.ID = types2.AirConditioningSwitch
	cmd.ThingID = req.ThingId

	params := make(map[string]interface{})
	params["status"] = req.Status
	params["status"] = req.Status
	cmd.Params = params
	result, err := common.CtrlResp(&cmd)
	fmt.Println("AirConditioningSwitch", cmd)
	Log.Log.Infof("[%s] [%v] AirConditioningSwitch cmd %v", requestId, uid, cmd)
	Log.Log.Infof("[%s] [%v] AirConditioningSwitch err %v result %v", requestId, uid, err, result)
	if err == nil {
		resp.Success(result)
	} else {
		resp.ErrorCode(types2.Fail, "")
	}
	return
}

func AirConditioningDispatch(c *gin.Context) {
	requestId, _ := c.Get("RequestId")
	uid := c.GetInt64("uid")
	resp := types2.NewResult(c)
	var req types2.ReqAirConditioningDispatch
	if err := c.ShouldBind(&req); err != nil {
		Log.Log.Errorf("[%s] [%v] err:=%v", requestId, uid, err)
		resp.ErrorCode(types2.ParamsError, "")
		return
	}
	var cmd ctrltype.CtrlCmd
	cmd.ID = types2.AirConditioningDispatch
	cmd.ThingID = req.ThingId
	params := make(map[string]interface{})
	params["SetTemperature"] = req.Temperature
	params["mod"] = req.Mod
	params["speed"] = req.Speed
	params["control"] = req.Control
	cmd.Params = params
	result, err := common.CtrlResp(&cmd)
	fmt.Println("AirConditioningDispatch", cmd)
	Log.Log.Infof("[%s] [%v] AirConditioningDispatch cmd %v", requestId, uid, cmd)
	Log.Log.Infof("[%s] [%v] AirConditioningDispatch err %v result %v", requestId, uid, err, result)
	if err == nil {
		resp.Success(result)
	} else {
		resp.ErrorCode(types2.Fail, "")
	}
	return
}
